package com.sun.controllers.users;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.sun.dto.users.LoginDto;
import com.sun.services.users.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
public class AuthorizationController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @SaIgnore
    public SaResult login(@RequestBody LoginDto loginDto) {
        return userService.login(loginDto.getUsername(), loginDto.getPassword());
    }

    @GetMapping("/logout")
    public SaResult logout() {
        StpUtil.logout();
        return SaResult.ok();
    }


    @GetMapping("/ReloadUserRole/{id}")
    private SaResult ReloadUserRole(@PathVariable Long id) {

        return userService.ReloadUserRole(id);
    }


}
